#pragma once
#include "ThreadSafer.h"
#include "NetMessage.h"
#include <list>
using namespace std;

namespace _FOGGE_
{
	namespace _NET_
	{

		class ReliableOutQueue 
			: public _FOGGE_::_THREAD_::ThreadSafer  
		{
		protected:
			list<UDPNetMessage *> m_Messages;
			DWORD               m_dwCurrentPacketID;
			DWORD				m_dwCount;  // number of packets added to this queue.
			_FOGGE_::_THREAD_::ThreadBlocker		m_Blocker;
			
		public:
			ReliableOutQueue();
			virtual ~ReliableOutQueue();
			
			void        Clear();
			void        AddMessage(UDPNetMessage * ptrMessage);
			void        RemoveMessage( DWORD msgID );

			// Do not remove a message from the queue, but get the message.
			// ReturnPacket() MUST be called when you after call GetMessageForResend,GetMessageByIndex,GetPreviousMessage,PeekMessage
			//or the critical section will not be released (BAD!)
			// Also: do NOT free the message (BAD!)
			UDPNetMessage *   GetMessageForResend( DWORD waitTime);
			const UDPNetMessage *	GetMessageByIndex( int index);
			const UDPNetMessage *	GetPreviousMessage( DWORD msgID);
			const UDPNetMessage *	PeekMessage( DWORD msgID );
			void        ReturnMessage(const UDPNetMessage ** ptrptrMessage);

			
			DWORD       GetLowestID();
			bool        IsEmpty();
			int			Size();
			
			inline DWORD GetCurrentID() { return m_dwCurrentPacketID; }
			DWORD GetCount()			{ return m_dwCount;			}
		};
	}
}
